import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/**
 * @author jekyllxv
 */
public class ThreadTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        List<Integer> bigList = new ArrayList<Integer>();

        for (int i = 1; i<=67;i++){
            bigList.add(i);
        }
        int queueSize = 13;
        int maxThreads = bigList.size()/queueSize;
        List<Future> futures = new ArrayList<Future>();

        CopyOnWriteArrayList<Integer> threadList = new CopyOnWriteArrayList<>();
        ExecutorService ts = new ThreadPoolExecutor(4,
                maxThreads,
                6000,
                TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(queueSize)
               );
        for (Integer integer : bigList) {
            Future listFuture =   ts.submit(new Runnable() {

                @Override
                public void run() {
                    if(integer %2==1){
                        threadList.add(integer);
                    }
                    System.out.println( Thread.currentThread().getName()+threadList);
                }
            });
            futures.add(listFuture);
//            ts.execute(new Runnable() {
//                @Override
//                public void run() {
//                    if(integer %2==1){
//                        threadList.add(integer);
//                    }
//                    System.out.println( Thread.currentThread().getName()+threadList);
//                }
//            });

        }
        futures.forEach(future -> {
            try {
                future.get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        });





        System.out.println(threadList);


    }

}


